<template>
  <div class="nav-head top">
    <div class="content">
      <div class="box-1">
        <el-row :gutter="40">
          <el-col :span="8">
            <img src="https://res.songzhaopian.cn/rouzao-custom-platform/icon-v2.png" alt="" />
            <div class="slogan">专注一件起订的柔性供应链</div>
          </el-col>
          <el-col :span="12">
            <el-input v-model="value" style="width: 440px" placeholder="搜索你想要的商品">
              <template #append>搜索</template>
            </el-input>
          </el-col>
          <el-col :span="4">
            <template v-if="isLogin">
              <el-divider direction="vertical" />
              <div @click="toPath('/notification')" class="icon-wrap">
                <i class="iconfont icon-remind"></i>
              </div>
              <el-divider direction="vertical" />
            </template>
            <div class="flex items-center text-nowrap user-wrap">
              <template v-if="isLogin">
                <el-avatar :src="userInfo.avatar" :size="35"> </el-avatar>
                <span class="pl-10">{{ userInfo.name }}</span>
                <i class="iconfont icon-sort-down"></i>
                <div class="user-list">
                  <div class="content">
                    <div class="user-item" @click="toPath('/user/my')">
                      个人中心
                    </div>
                    <div @click="handleLogout" class="mt-20 user-item">退出登录</div>
                  </div>
                </div>
              </template>
              <template v-else>
                <el-avatar :size="35"> </el-avatar>
                <el-button @click="handleShowDialog" class="pl-10" text>点击登录</el-button>
              </template>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="nav-tab">
        <el-row class="text-[18px]">
          <el-col :span="colSpanTab">
            <el-button @click="toPath('/home')" link>首页</el-button>
          </el-col>
          <el-col :span="colSpanTab">
            <el-button @click="toPath('/studyCenter')" link>学习中心</el-button>
          </el-col>
          <el-col :span="colSpanTab">
            <el-button @click="toPath('/products')" link>全部商品</el-button>
          </el-col>
          <el-col :span="colSpanTab">
            <el-button @click="toPath('/myProduct/list')" link>我的商品</el-button>
          </el-col>
          <el-col :span="colSpanTab">
            <el-button @click="toPath('/order/list')" link>订单管理</el-button>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useLoginStore } from '@/stores/login'
const loginStore = useLoginStore()
const value = ref('')
const colSpanTab = ref(4)
const router = useRouter()

function toPath (path) {
  router.push({
    path,
  })
}
const isLogin = computed(() => loginStore.isLoggedIn)
const userInfo = computed(() => loginStore.user)
function handleShowDialog () {
  loginStore.show()
}
function handleLogout () {
  loginStore.logout()
}
</script>

<style lang="scss" scoped>
.nav-head {
  height: 120px;
  box-shadow: rgba(0, 0, 0, 0.12) 0px 0px 10px;
  position: relative;
  z-index: 1;
  background-image: url('http://res.songzhaopian.cn/rouzao-custom-platform/assets/bg-2b457fc3.jpg');
  background-position: center center;

  .content {
    width: 1180px;
    margin: 0 auto;

    .icon-wrap {
      i {
        cursor: pointer;
      }
    }

    .user-wrap {
      position: relative;

      .user-list {
        display: none;

        .user-item {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 240px;
          height: 40px;
          box-sizing: border-box;
          border: 1px solid #e6e8ec;
          border-radius: 90px;
          font-size: 14px;
          cursor: pointer;
          color: #23262f;
        }
      }

      &:hover {
        .user-list {
          z-index: 9999;
          display: block;
          position: absolute;
          top: 10px;
          right: 0;

          .content {
            display: flex;
            flex-direction: column;
            margin-top: 40px;
            width: 292px;
            padding: 30px 26px;
            box-sizing: border-box;
            background: #fcfcfd;
            border-radius: 5px;
            z-index: 10;
            box-shadow: 0 40px 32px -24px rgba(15, 15, 15, 0.12);
          }
        }
      }
    }
  }

  .iconfont {
    padding: 0 10px;
    font-size: 20px;
  }

  .el-row {
    padding: 15px 0;

    .el-col {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .slogan {
      background-image: url('//res.songzhaopian.cn/rouzao-custom-platform/solgen.png');
      margin-left: 16px;
      height: 18px;
      width: 228px;
      background-size: contain;
      font-size: 0px;
      background-repeat: no-repeat;
    }

    img {
      height: 30px;
    }
  }

  .nav-tab {
    padding: 0 160px;

    .el-button {
      font-size: 18px;
    }
  }
}
</style>
